'''
Created on 12/10/2011

@author: User
'''
import unittest
from Appender import CsvAppender, XmlAppender
from Logger import LOGLEVEL_NONE, LOGLEVEL_ERROR, LOGLEVEL_NORMAL, LOGLEVEL_VERBOSE, LOGLEVEL_DEBUG

class TestAppender(unittest.TestCase):

    def testCreateAppenders(self):
        self.appender = XmlAppender(".", LOGLEVEL_NONE)
        self.assertIsInstance(self.appender, XmlAppender, "Error creating a new XmlAppender")
        self.appender = CsvAppender(".", LOGLEVEL_NONE)
        self.assertIsInstance(self.appender, CsvAppender, "Error creating a new CsvAppender")
    
    def testAllLogLevels(self):
        self.appender = XmlAppender(".", LOGLEVEL_NONE)
        self.assertIsInstance(self.appender, XmlAppender, "Error creating a new XmlAppender - LOGLEVEL_NONE")
        self.appender = CsvAppender(".", LOGLEVEL_NONE)
        self.assertIsInstance(self.appender, CsvAppender, "Error creating a new CsvAppender - LOGLEVEL_NONE")
        
        self.appender = XmlAppender(".", LOGLEVEL_ERROR)
        self.assertIsInstance(self.appender, XmlAppender, "Error creating a new XmlAppender - LOGLEVEL_ERROR")
        self.appender = CsvAppender(".", LOGLEVEL_ERROR)
        self.assertIsInstance(self.appender, CsvAppender, "Error creating a new CsvAppender - LOGLEVEL_ERROR")
        
        self.appender = XmlAppender(".", LOGLEVEL_NORMAL)
        self.assertIsInstance(self.appender, XmlAppender, "Error creating a new XmlAppender - LOGLEVEL_NORMAL")
        self.appender = CsvAppender(".", LOGLEVEL_NORMAL)
        self.assertIsInstance(self.appender, CsvAppender, "Error creating a new CsvAppender - LOGLEVEL_NORMAL")
        
        self.appender = XmlAppender(".", LOGLEVEL_VERBOSE)
        self.assertIsInstance(self.appender, XmlAppender, "Error creating a new XmlAppender - LOGLEVEL_VERBOSE")
        self.appender = CsvAppender(".", LOGLEVEL_VERBOSE)
        self.assertIsInstance(self.appender, CsvAppender, "Error creating a new CsvAppender - LOGLEVEL_VERBOSE")
        
        self.appender = XmlAppender(".", LOGLEVEL_DEBUG)
        self.assertIsInstance(self.appender, XmlAppender, "Error creating a new XmlAppender - LOGLEVEL_DEBUG")
        self.appender = CsvAppender(".", LOGLEVEL_DEBUG)
        self.assertIsInstance(self.appender, CsvAppender, "Error creating a new CsvAppender - LOGLEVEL_DEBUG")
        
    def testOpenCloseFileXmlAppender(self):
        self.appender = XmlAppender("test.xml", LOGLEVEL_NONE)
        self.assert_(self.appender.openFile(), "Error opening XML appender file")
        self.assert_(self.appender.closeFile(), "Error closing XML appender file")
    
    def testOpenCloseFileCsvAppender(self):
        self.appender = CsvAppender("test.csv", LOGLEVEL_NONE)
        self.assert_(self.appender.openFile(), "Error opening CSV appender file")
        self.assert_(self.appender.closeFile(), "Error closing CSV appender file")
    
    
if __name__ == "__main__":
    unittest.main()